package com.idp.web.test.service.impl;

import com.idp.web.test.service.ProductService;
import com.idp.web.test.dao.ProductDao;
import com.idp.web.test.entity.Product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.idp.common.persistence.Page;
import com.idp.common.util.ResourceUtils;

/**
 * 
 * 产品service实现类
 * 
 * <pre>
 * 	历史记录：
 * 	2017-06-02 Amber
 * 	新建文件
 * </pre>
 * 
 * @author
 * 
 *         <pre>
 * SD
 * 	Amber
 * PG
 *	Amber
 * UT
 *
 * MA
 *         </pre>
 * 
 * @version $Rev$
 *
 *          <p/>
 *          $Id$
 *
 */
@Service("productService")
public class ProductServiceImpl implements ProductService {

	@Resource
	private ProductDao productDao;

	@Override
	public Page<Product> findByPage(Product product, Page<Product> page) {

		page.setResult(productDao.find(product, page));

		return page;
	}

	@Override
	public List<Product> findBySearch(Product product) {
		return productDao.find(product);
	}

	@Override
	public Product getById(Integer id) {
		return productDao.getById(id);
	}

	@Override
	public Product getByCode(String code) {
		return productDao.getByCode(code);
	}


	@Override
	public void add(Product product) {
		product.setProductStatusId(2); // 2 -> 缺货
		productDao.add(product);
	}

	@Override
	public void update(Product product) {

		productDao.update(product);
	}

	@Override
	public void delete(Integer id) {

		productDao.delete(id);
	}

	@Override
	public Page<Product> sreachByWarehouseAndProductNameAndProductStatus(Integer warehouseId, Integer productStatusId,
			String productName , Page<Product> page) {
		Map<String, Object> map = new HashMap<>();
		map.put("warehouseId", warehouseId);
		map.put("productStatusId", productStatusId);
		map.put("productName", productName);
		page.setResult(productDao.sreachByWarehouseAndProductNameAndProductStatus(map , page));
		return page;
	}

	@Override
	public void updateNotNull(Product product) {
		productDao.updateNotNull(product);
	}
}